﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;


namespace zlh.banganyemian
{
    public partial class banjiangcheng : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Page_PreInit(object sender, EventArgs e)
        {
            if (Session["color"] == "1")
            {
                Page.Theme = "1";

            }
            else if (Session["color"] == "2")
            {
                Page.Theme = "2";
            }
            else
            {
                Page.Theme = "3";
            }
        }

        protected void readbtn_Click(object sender, EventArgs e)
        {
            string strSql = "SELECT   stuNo, stuName, jiangchengleibie, text, jiafenshu FROM      jiangcheng WHERE   (stuNo = @stuNo)";
            SqlParameter[] pms = new SqlParameter[1];
            pms[0] = new SqlParameter("@stuNo", this.stuno.Text);
            SqlDataReader dr = SqlHelper.ExecuteReader(strSql, pms);
            if (dr.Read())
            {
                this.stuname.Text = dr["stuName"].ToString();
                this.leibietxt.Text = dr["jiangchengleibie"].ToString();
                this.xinxitxt.Text = dr["text"].ToString();
                this.jiafentxt.Text = dr["jiafenshu"].ToString();               
            }
            dr.Close();//关闭
        }

        protected void update_Click(object sender, EventArgs e)
        {
            
             StringBuilder sb = new StringBuilder(1024);
            sb.Append("UPDATE  jiangcheng ");
            sb.Append("SET         stuNo = @stuNo, stuName = @stuName,  jiangchengleibie = @jiangchengleibie, text = @text, jiafenshu = @jiafenshur");           
            sb.Append("WHERE   (stuNo = @stuNo) ");

            SqlParameter[] pms = new SqlParameter[5];
            pms[0] = new SqlParameter("@stuNo", this.stuno.Text);
            pms[1] = new SqlParameter("@stuName", this.stuname.Text);
            pms[2] = new SqlParameter("@jiangchengleibie", leibietxt.Text);
            pms[3] = new SqlParameter("@text", this.xinxitxt.Text);
            pms[4] = new SqlParameter("@jiafenshu", this.jiafentxt.Text);
           

            int intResult = SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
            this.lblInfo.Text = (intResult < 1) ? "更新失败！" : "更新" + intResult.ToString() + "条记录！";
        }

        protected void delete_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder(1024);
            sb.Append("DELETE FROM jiangcheng ");
            sb.Append("WHERE   (stuNo = @stuNo) ");

            SqlParameter[] pms = new SqlParameter[5];
            pms[0] = new SqlParameter("@stuNo", this.stuno.Text);
            pms[1] = new SqlParameter("@stuName", this.stuname.Text);
            pms[2] = new SqlParameter("@jiangchengleibie", leibietxt.Text);
            pms[3] = new SqlParameter("@text", this.xinxitxt.Text);
            pms[4] = new SqlParameter("@jiafenshu", this.jiafentxt.Text);

            int intResult = (int)SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
            this.lblInfo.Text = (intResult < 1) ? "删除失败！" : "删除" + intResult.ToString() + "条记录！";
        }

        protected void add_Click(object sender, EventArgs e)
        {
             StringBuilder sb = new StringBuilder(1024);
            sb.Append("INSERT INTO jiangcheng ");
            sb.Append("                (stuNo, stuName, jiangchengleibie, text, jiafenshu) ");
            sb.Append("VALUES   (stuNo = @stuNo, stuName = @stuName,  jiangchengleibie = @jiangchengleibie, text = @text, jiafenshu = @jiafenshur) ");

           SqlParameter[] pms = new SqlParameter[5];
            pms[0] = new SqlParameter("@stuNo", this.stuno.Text);
            pms[1] = new SqlParameter("@stuName", this.stuname.Text);
            pms[2] = new SqlParameter("@jiangchengleibie", leibietxt.Text);
            pms[3] = new SqlParameter("@text", this.xinxitxt.Text);
            pms[4] = new SqlParameter("@jiafenshu", this.jiafentxt.Text);
           
          
            int intResult = (int)SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
            this.lblInfo.Text = (intResult < 1) ? "新增失败！" : "新增" + intResult.ToString() + "条记录！";
        }
     }
 }
